// miniprogram/pages/poetry/oldbook/menu/menu.js
const poetry_db = wx.cloud.database().collection("poetry")
const $ = wx.cloud.database().command

Page({
  data: {
    oldBook: {}
  },
  onLoad: function (options) {
    console.log(options.name)
    var bookName = options.name
    wx.setNavigationBarTitle({
      title: bookName
    })
    poetry_db.where({
      bookName: bookName,
      year: $.exists(true)
    }).get({
      success: (res) => {
        console.log(res)
        var oldBook = res.data[0]
        this.setData({
          oldBook: oldBook
        })
      }
    })
  },
  onShareAppMessage: function () {

  },
  //章节点击监听
  onChapterClick(e) {
    console.log(e)
    var bookName = this.data.oldBook.bookName
    var index = e.currentTarget.dataset.index
    wx.navigateTo({
      url: '../detail/detail?bookName=' + bookName + '&curIndex=' + index
    })
  }
})